home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 128 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.1 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Throwing an exception from within a signal handler
  5. Date: 24 Jan 1996 11:34:57 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <9601241005.AA12922@lts.sel.alcatel.de>
  9. References: <4dgj4m$9la@engnews1.Eng.Sun.COM> <DLCosx.Hn1@falcon.daytonoh.attgis.com> <KANZE.96Jan19122409@gabi.gabi-soft.fr>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Wed, 24 Jan 96 11:05:23 +0100
  12. In-Reply-To: kanze@gabi.gabi-soft.fr's message of 19 Jan 1996 21:03:12 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMQaJ8ky4NqrwXLNJAQGCygH+N+OwANhei8wovaW/q85T3qfK6pLMN7x0
  15.     zSD1IM7PsoWJnuzkYp7xmJcTzWDCSUYP2qciEsUPhW3aQ8l4TTtWfQ==
  16.     =wEP1
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. G. Bowden Wise writes:
  20.  
  21. |> J. Kanze wrote:
  22.  
  23. |> > I use reference counted pointers a lot, but they have their own set of
  24. |> > problems.  I can very well understand the committees reluctance to 
  25. |> > adapt them.
  26.  
  27. |> Can you share with us the problems with reference counter pointers?
  28. |> How do those problems compare with the auto_ptr problems?  Perhaps
  29. |> we need some kind of hybrid between the two.
  30.  
  31. The problems are not so much with use, but with how to standardize.
  32.  
  33. There are two distinct approaches with regards to reference counted
  34. pointers: invasive and non-invasive.
  35.  
  36. Invasive reference counting involves significant constraints with
  37. regards to the counted objects.  None of the basic types meet these
  38. constraints, nor can they be made to.  None of the other types in the
  39. library meet them, either.  In this case, the committee could eventual
  40. change this, but in many cases (iterators, for example), meeting the
  41. constraints would involve significant overhead, which would then be
  42. paid by everyone, including those who didn't use reference counting.
  43. (For a good discussion of invasive reference counting, see Scott
  44. Meyers' new book.)
  45.  
  46. Non-invasive reference counting has significant run time overhead.  In
  47. fact, the overhead is enough to make invasive reference counting the
  48. prefered method in most cases (IMHO).  (For an example of non-invasive
  49. reference counting, see Barton and Nackman.)  My experience suggests
  50. that in most cases where reference counting is appropriate, I am
  51. implementing reference semantics for polymorphic objects.  In these
  52. cases, the invasive approach is definitly to be prefered.  I suspect
  53. that if the standard had adapted a non-invasive approach, I probably
  54. would not have used it anyway.  (My own reference counted pointers
  55. require the referenced object to inherit from GB_RefCntObj.)
  56.  
  57. Another potential problem: reference counted pointers do not work when
  58. there are cycles in the reference chain.  As such, there actual field
  59. of use is much more restricted than one would like (for something in
  60. the standard); I use them because most of my objects fall into
  61. hierarchial structures, which forbid cycles.  But for many application
  62. domains, the restriction that the references not contain cycles is
  63. non-trivial.  I can imagine that some people would oppose their
  64. presence in the standard on the grounds that we do not want to
  65. standardize something that is so intrinsically dangerous; it might
  66. give people a false sense of security.  (By the same logic, of course,
  67. we should eliminate gets, and even sprintf, from the standard.
  68. History rules, however.)
  69.  
  70. In view of these two problems, I myself do not see a real role for
  71. reference counted pointers in the standard.  Note that neither of
  72. these problems affect auto_ptr.  (In theory, I guess, you could create
  73. a cycle with auto_ptr, but I cannot really imagine the case occuring
  74. in real code.)
  75.  
  76. --
  77. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  78. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  79. Conseils, itudes et rialisations en logiciel orienti objet --
  80.                 -- A la recherche d'une activiti dans une region francophone
  81. ---
  82. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  83.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  84.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  85.